var GameData = {
    playerinfo:{},
};

GameData.updateEnterDeskInfo = function(info){
    this.mine_seatid = null ;
    if(info.op_uin==UserInfoModel.info.uin){
        this.playerinfo = {};
        this.obplayerinfo = {}; //ob 旁观的
    }
    for(var index in info.users){
        var user = info.users[index];

        if (user.status ==  GameConfig.playerStatus.USER_STATE_STAND){
            this.obplayerinfo[user.uin] = this.obplayerinfo[user.uin] || {};
            for(var attribute in user){
                this.obplayerinfo[user.uin][attribute] = user[attribute];
            }
        }else{
            this.playerinfo[user.uin] = this.playerinfo[user.uin] || {};
            for(var attribute in user){
                this.playerinfo[user.uin][attribute] = user[attribute];
            }
            if(user.uin==UserInfoModel.info.uin)
            {   
                
                this.mine_seatid = user.seatid;
                Log.logd(this.mine_seatid,"this.mine_seatid----");
            }else{
                Log.logd("this.mine_seatid  no----");
            }
            this.playerinfo[user.uin].card_type = user.card_type || 0;
        }
    }
    for(var index in info){
        if(index!="users")
        {
            this[index] = info[index];
        }
    }
    Log.logd(this.mine_seatid,"this.mine_seatid----end");
    console.log("this.playerinfo-->");
    dump(this.playerinfo);
};
GameData.updateGameStartInfo = function(info){
    console.log("this.playerinfo-->");
    dump(this.playerinfo);
    console.log("info-->");
    dump(info);
    this.playerinfo[UserInfoModel.info.uin].cards = info.card || {};
    for(var index in info){
        if(index!="users")
        {
            this[index] = info[index];
        }
        else
        {
            
            for(var k in info[index])
            {
                var user = info[index][k];
                for(var attribute in user){
                   if(user.status ==  GameConfig.playerStatus.USER_STATE_STAND)
                    {
                       this.obplayerinfo[user.uin][attribute] = user[attribute];
                   }else{
                       this.playerinfo[user.uin][attribute] = user[attribute];
                   }
                    
                }
            }
        }
    }
};
GameData.updateInfo = function(info){
    for(var index in info){
        this[index] = info[index];
    }
};
GameData.updatePlayerInfo = function(info){
    this.playerinfo[info.uin].cards = info.card || [] ;
};
GameData.updateLastCardInfo = function(info){
    this.playerinfo[UserInfoModel.info.uin].cards = this.playerinfo[UserInfoModel.info.uin].cards || {};
    this.playerinfo[UserInfoModel.info.uin].cards["4"]=info.card;
    this.playerinfo[UserInfoModel.info.uin].card_type=info.card_type || 0;
    this.out_card_time = info.out_card_time;
    if(this.playerinfo[UserInfoModel.info.uin]["cards"].length == 5){
        console.log("计算牌型----------------dsdadsadsad");
        dump(this.playerinfo[UserInfoModel.info.uin]["cards"]);
    }
};
GameData.updateGameEndInfo = function(data){
    for(var k in data.result){
        var tempInfo = data.result[k] ;
        var user = this.playerinfo[tempInfo.uin];
        for(var index in tempInfo){
            user[index] = tempInfo[index];
        }
        user["cards"] = tempInfo.card ;
    }
};
//获得玩家对应的桌子号
GameData.getUserSeatP = function(seatId){
    Log.logd(this.mine_seatid,"this.mine_seatid----dsada");
    if(this.mine_seatid == null){
        return  seatId ;
    }else{
        var cut = seatId - this.mine_seatid ;
        if (cut < 0){
            cut = this.PlayerNum+cut;
        }
        return cut;
    }
},
GameData.getUinByTSeat = function(seatId){
    for(var k in this.playerinfo){
        var user = this.playerinfo[k];
        var tempSeat = this.getUserSeatP(user.seatid);
        if(tempSeat==seatId){
            return user.uin
        }
    }
    return null ;
},

GameData.getUserByUin = function(uin){
    return this.playerinfo[uin] ;
},

GameData.judgeSelfIsPangGuan = function(){
      for(var k in this.playerinfo){
        if(this.playerinfo[k].uin==UserInfoModel.info.uin){
            var user = this.playerinfo[k];
            if(user.status == GameConfig.playerStatus.UN_READY){
                return true ;
            }else{
                return false ;
            }
        }
     }
},

// //获得玩家对应的桌子号
// GameData.getUserSeatByUin = function(uid){
//     Log.logd(this.mine_seatid,"this.mine_seatid----dsada");
//         var cut = seatId - this.mine_seatid;
//         if (cut < 0){
//             cut = 5+cut;
//         }
//         return cut;
//     },

window.GameData = GameData;